
<%
Sub pagingButton(PageIndex, TotalPages)
	
	Dim Counter		'Page Counter
	Dim strHTML		'HTML code
	Dim strPath		'Base path of the page
	Dim qryStr		'query string
	Dim iBeginInd	'Start index of paging
	Dim iEndInd		'End index of paging
		
	
	If PageIndex > 1 Then
		iEndInd = 10 + PageIndex - 1
	End if
	
	If PageIndex > 10 Then
		iBeginInd = PageIndex - 10
	End if
	
	iBeginInd	= PageIndex - 10 
	iEndInd		= 10 + PageIndex - 1
	
	strPath = Request.ServerVariables("PATH_INFO")
	' Maintain query string
	qryStr = Request.ServerVariables("QUERY_STRING")
	If qryStr <> "" Then
		If InStr(qryStr, "sort=")>0 Then
			qryStr = "&" & Mid(qryStr, InStr(qryStr, "sort="))
		Else
			qryStr = ""
		End if
	End if	

	
	strHTML = "<div align='center'>" 
	
	If TotalPages > 1 Then		
			
		'Previous Button [style='float:left']
		If PageIndex > 1 Then
			
			strHTML = strHTML & "<a href="& strPath &"?PageIndex=" & (PageIndex-1) & qryStr &  ">&laquo;Prev</a> "
						
		End If				
		
		
		'Skip paging
		If iBeginInd < 1 Then iBeginInd = 1
		If iEndInd > TotalPages Then iEndInd = TotalPages
		
		
		
		'Page Navigation
		strHTML = strHTML & "[ Page: " 
		For Counter=iBeginInd to iEndInd	
			
			If Counter = PageIndex Then
			
				strHTML = strHTML & "<b>"& Counter &"&nbsp;</b>"
			Else
				strHTML = strHTML & "<a href="& strPath &"?PageIndex="& Counter & qryStr & ">"& Counter & "</a>&nbsp;"
			End If
			
			
			If Counter < iEndInd then
				strHTML = strHTML & " | "										
			End if 	
			
		Next
		strHTML = strHTML & "]" 
		
		
		'Next Button [style='float:right']
		If PageIndex < TotalPages Then
			strHTML = strHTML & " <a href="& strPath &"?PageIndex=" & (PageIndex+1) & qryStr & ">Next&raquo;</a>"
		End If
		
	
	End If
	
	strHTML = strHTML & "</div>"
	
	
	'Render to browser
	Response.Write(strHTML)

End Sub

%>

